package com.example.health;

import java.io.BufferedInputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CustomAdapter2 extends ArrayAdapter<Object> {
	
	private ArrayList<LocalData> data;
	View v;
//	ImageView image;

	public CustomAdapter2(Context context, int textViewResourceId,
			ArrayList items) {
		super(context, textViewResourceId, items);
		this.data = items;
	}
		
	public View getView(int position, View convertView, ViewGroup parent){
		
		v = convertView;
		
		if(v == null){
			LayoutInflater vi = (LayoutInflater)getContext().getSystemService(
						Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.serach_itemlist, null);
		}
		
		LocalData item = data.get(position);
		if(item != null){
//			image = (ImageView)v.findViewById(R.id.image);
			
			TextView v_title = (TextView)v.findViewById(R.id.title);
			TextView v_phone = (TextView)v.findViewById(R.id.telephone);
			TextView v_address= (TextView)v.findViewById(R.id.roadaddress);
			
			v_title.setText("업체명 : " +item.title);
			v_phone.setText("전화번호 : " +item.telephone);
			v_address.setText("도로명주소 : " + item.roadAddress);
			
			//리스트에서 보여주기 위한 이미지를 파싱
/*			URL imageUri;
			try{
				imageUri = new URL(item.image);
				HttpURLConnection con = (HttpURLConnection)imageUri.openConnection();
				BufferedInputStream bis = new BufferedInputStream(con.getInputStream(), 10240);
				Bitmap bm = BitmapFactory.decodeStream(bis);
				bis.close();
				image.setImageBitmap(bm);
			}catch(Exception e){
				e.printStackTrace();
			}*/
		}
		return v;
	}

}
